The cosine of angle (degrees, 0 = east, counterclockwise) - a value from -1 to 1.
angle_cos(angle) -> real| Name | Type |
|---|---|
angle | real |
real
The cosine of angle - degrees, 0 is east, counterclockwise, the same convention dir_to and every other angle in GBML already uses. Always somewhere between -1 and 1.
angle_sin's own twin: together they turn a bare angle into a point on a circle - angle_cos gives the sideways half, angle_sin the up/down half.
direction += 3;
x = xstart + (angle_cos(direction) * 24);
y = ystart - (angle_sin(direction) * 24);Circles this object around wherever it spawned, 24 pixels out - direction doubles as the orbit's own current angle here, advancing a little more every frame. angle_cos is the half that needs no sign flip: the room's X axis already grows the same direction a maths textbook's own cosine does, right. dir_x already wraps exactly this line (length * angle_cos(direction)) - reach for dir_x/dir_y directly instead of writing it out by hand whenever a plain direction-and-length is all a piece of code actually needs.
The same algorithm as angle_sin, at the same measured accuracy: checked against true cosine over 57,601 sample angles, the worst answer found was off by 0.000434 - under two of real's own smallest steps (1/4096), no worse than real already is. Works for any angle, no pre-wrapping into 0-360 needed.
angle_sin’s own twin, the same algorithm (its degrees cosine function) at the same measured accuracy (0.000434 largest error found, checked against true cosine over 57,601 sample angles) and the same cost - works for any angle, no pre-wrapping needed.